package com.sztx.pay.center.core.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.sztx.pay.center.common.util.StringUtil;
import com.sztx.pay.center.core.service.BillnoHelperService;
import com.sztx.pay.center.core.service.BillnoService;
import com.sztx.pay.center.core.service.bean.BillnoModel;
import com.sztx.se.core.service.impl.BaseServiceImpl;

@Service
public class BillnoServiceImpl extends BaseServiceImpl implements BillnoService {
	
	@Autowired
	BillnoHelperService helperService;
	
	
	@Override
	public String nextUserAccount( ) {
		
		return getNo(1001);
	}
	
	@Override
	public String nextB2CTradeNo() {
		return getNo(1002);
	}

	@Override
	public String nextWithdrawNo() {
		return getNo(1003);
	}

	@Override
	public String nextRefundNo() {
		return getNo(1004);
	}

	@Override
	public String nextChargeNo() {
		return getNo(1005);
	}

	@Override
	public String nextTransferNo() {
		return getNo(1006);
	}

	@Override
	public String nextSettleNo() {
		return getNo(1007);
	}

	@Override
	public String nextNotifyNo() {
		return getNo(1008);
	}
	
	@Override
	public String nextUserAccountFlow() {
		return getNo(1009);
	}
	
	@Override
	public String nexBindCardNo() {
		return getNo(1010);
	}
	

	@Override
	public String nexPayFlowNo() {
		return getNo(1011);
	}
	
	@Override
	public String nexPayFlowBatchNo() {
		return getNo(1012);
	}
	@Override
	public String nexCallBackNo() {
		return getNo(1013);
	}

	@Override
	public String nextNo(int templateId) {

		return getNo(templateId);
	}

	public String getNo(int templateId){		
		StringBuilder result = new StringBuilder();
		BillnoModel model = helperService.getValue(templateId, null);
		
		if (StringUtil.isNotBlank(model.getPrefix())) {
			result.append(model.getPrefix());
		}
		
		if (model.getType() == 2) {
			result.append(model.getDate());
		}
		
		if (StringUtil.isNotBlank(model.getOrderStyle())) {
			result.append(StringUtil.getSeq(model.getOrderStyle(), model.getCurrentValue()));
		}else {
			result.append(model.getCurrentValue());
		}

		return result.toString();		
	}

	@Override
	public String nextMappingOrderNo() {
		return getNo(1014);
	}

	





}
